import * as Blockly from 'blockly/core';


const GATT_HUE = "#1860A1";

export const gattServer_device_init = {
    init: function () {
        this.appendValueInput("name")
            .setCheck(null)
            .appendField("BLE设备初始化名称");
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setColour(GATT_HUE);
        this.setTooltip("");
        this.setHelpUrl("");
    }
};

export const gattServer_server_init = {
    init: function () {
        this.appendDummyInput()
            .appendField("将变量")
            .appendField(new Blockly.FieldTextInput("pServer"), "var")
            .appendField("初始化为BLE服务端");
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setColour(GATT_HUE);
        this.setTooltip("");
        this.setHelpUrl("");
    }
};

export const gattServer_service_init = {
    init: function () {
        this.appendDummyInput()
            .appendField("将变量")
            .appendField(new Blockly.FieldTextInput("pService"), "var")
            .appendField("初始化为BLE服务端")
            .appendField(new Blockly.FieldTextInput("pServer"), "server")
            .appendField("的GATT服务");
        this.appendValueInput("UUID")
            .appendField("UUID");
        this.setInputsInline(false);
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setColour(GATT_HUE);
        this.setTooltip("");
        this.setHelpUrl("");
    }
};

export const gattServer_char_init = {
    init: function () {
        this.appendDummyInput()
            .appendField("将变量")
            .appendField(new Blockly.FieldTextInput("pCharacteristic"), "var")
            .appendField("初始化为GATT服务")
            .appendField(new Blockly.FieldTextInput("pService"), "service")
            .appendField("的GATT特征");
        this.appendDummyInput()
            .appendField("客户端可读")
            .appendField(new Blockly.FieldCheckbox("true"), "read")
            .appendField("客户端可写")
            .appendField(new Blockly.FieldCheckbox("true"), "write")
            .appendField("服务端可发送通知")
            .appendField(new Blockly.FieldCheckbox("true"), "notify");
        this.appendValueInput("UUID")
            .setCheck(null)
            .appendField("UUID");
        this.setInputsInline(false);
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setColour(GATT_HUE);
        this.setTooltip("");
        this.setHelpUrl("");
    }
};

export const gattServer_set_char_value = {
    init: function () {
        this.appendValueInput("value")
            .setCheck(null)
            .appendField("将GATT特征")
            .appendField(new Blockly.FieldTextInput("pCharacteristic"), "var")
            .appendField("的值修改为");
        this.setInputsInline(false);
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setColour(GATT_HUE);
        this.setTooltip("");
        this.setHelpUrl("");
    }
};

export const gattServer_start_service = {
    init: function () {
        this.appendDummyInput()
            .appendField("启动GATT服务")
            .appendField(new Blockly.FieldTextInput("pService"), "var");
        this.setInputsInline(false);
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setColour(GATT_HUE);
        this.setTooltip("");
        this.setHelpUrl("");
    }
};

export const gattServer_advertising_init = {
    init: function () {
        this.appendDummyInput()
            .appendField("将变量")
            .appendField(new Blockly.FieldTextInput("pAdvertising"), "var")
            .appendField("初始化为BLE服务端")
            .appendField(new Blockly.FieldTextInput("pServer"), "Server")
            .appendField("的广播");
        this.setInputsInline(false);
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setColour(GATT_HUE);
        this.setTooltip("");
        this.setHelpUrl("");
    }
};

export const gattServer_start_advertising = {
    init: function () {
        this.appendDummyInput()
            .appendField("启动广播")
            .appendField(new Blockly.FieldTextInput("pAdvertising"), "advertising");
        this.setInputsInline(false);
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setColour(GATT_HUE);
        this.setTooltip("");
        this.setHelpUrl("");
    }
};

export const gattServer_char_notify = {
    init: function () {
        this.appendDummyInput()
            .appendField("通知客户端GATT特征")
            .appendField(new Blockly.FieldTextInput("pCharacteristic"), "char")
            .appendField("被更新");
        this.setInputsInline(false);
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setColour(GATT_HUE);
        this.setTooltip("");
        this.setHelpUrl("");
    }
};
/*
TODO: 以后再更新客户端块
*/